import pygame
import sys
from init_map import InitMap


class Map(InitMap):
    def __init__(self, *args):
        InitMap.__init__(self)

        self.key_yellow = pygame.image.load("../资源/图片/黄钥匙.jpg").convert_alpha()
        self.key_blue = pygame.image.load("../资源/图片/蓝钥匙.jpg").convert_alpha()
        self.key_red = pygame.image.load("../资源/图片/红钥匙.jpg").convert_alpha()
        self.hp_red = pygame.image.load("../资源/图片/红药.jpg").convert_alpha()
        self.hp_blue = pygame.image.load("../资源/图片/蓝药.jpg").convert_alpha()
        self.gem_red = pygame.image.load("../资源/图片/红宝石.jpg").convert_alpha()
        self.gem_blue = pygame.image.load("../资源/图片/蓝宝石.jpg").convert_alpha()
        self.white_warrior = pygame.image.load("../资源/图片/白衣武士.png").convert_alpha()
        self.shadow_soldier = pygame.image.load("../资源/图片/影子战士.png").convert_alpha()
        self.dark_leader = pygame.image.load("../资源/图片/冥队长.png").convert_alpha()
        self.ling_warrior = pygame.image.load("../资源/图片/灵武士.png").convert_alpha()

        self.hero_pos = (5, 4)
        self.up_pos = (5, 7)
        self.down_pos = (5, 3)
        self.variable_pos = {
            (2, 1): (self.key_yellow, '黄钥匙'),
            (2, 3): (self.key_yellow, '黄钥匙'),
            (4, 1): (self.key_blue, '蓝钥匙'),
            (1, 4): (self.key_blue, '蓝钥匙'),
            (0, 3): (self.hp_red, '红药'),
            (3, 0): (self.hp_red, '红药'),
            (0, 1): (self.hp_blue, '蓝药'),
            (1, 0): (self.gem_red, '红宝石'),
            (1, 2): (self.gem_blue, '蓝宝石'),
            (2, 0): (self.white_warrior, '白衣武士'),
            (2, 2): (self.white_warrior, '白衣武士'),
            (0, 0): (self.shadow_soldier, '影子战士'),
            (4, 0): (self.dark_leader, '冥队长_ss'),
            (0, 4): (self.dark_leader, '冥队长_ss'),
            (4, 2): (self.ling_warrior, '灵武士_ss'),
            (2, 4): (self.ling_warrior, '灵武士_ss'),
            (5, 0): (self.key_red, '红钥匙'),
            (8, 1): (self.key_yellow, '黄钥匙'),
            (8, 3): (self.key_yellow, '黄钥匙'),
            (6, 1): (self.key_blue, '蓝钥匙'),
            (9, 4): (self.key_blue, '蓝钥匙'),
            (10, 3): (self.hp_red, '红药'),
            (7, 0): (self.hp_red, '红药'),
            (10, 1): (self.hp_blue, '蓝药'),
            (9, 0): (self.gem_red, '红宝石'),
            (9, 2): (self.gem_blue, '蓝宝石'),
            (8, 0): (self.white_warrior, '白衣武士'),
            (8, 2): (self.white_warrior, '白衣武士'),
            (10, 0): (self.shadow_soldier, '影子战士'),
            (6, 0): (self.dark_leader, '冥队长_ss'),
            (10, 4): (self.dark_leader, '冥队长_ss'),
            (6, 2): (self.ling_warrior, '灵武士_ss'),
            (8, 4): (self.ling_warrior, '灵武士_ss'),
            (10, 5): (self.key_red, '红钥匙'),
            (8, 9): (self.key_yellow, '黄钥匙'),
            (8, 7): (self.key_yellow, '黄钥匙'),
            (6, 9): (self.key_blue, '蓝钥匙'),
            (9, 6): (self.key_blue, '蓝钥匙'),
            (10, 7): (self.hp_red, '红药'),
            (7, 10): (self.hp_red, '红药'),
            (10, 9): (self.hp_blue, '蓝药'),
            (9, 10): (self.gem_red, '红宝石'),
            (9, 8): (self.gem_blue, '蓝宝石'),
            (8, 10): (self.white_warrior, '白衣武士'),
            (8, 8): (self.white_warrior, '白衣武士'),
            (10, 10): (self.shadow_soldier, '影子战士'),
            (6, 10): (self.dark_leader, '冥队长_ss'),
            (10, 6): (self.dark_leader, '冥队长_ss'),
            (6, 8): (self.ling_warrior, '灵武士_ss'),
            (8, 6): (self.ling_warrior, '灵武士_ss'),
            (5, 10): (self.key_red, '红钥匙'),
            (2, 9): (self.key_yellow, '黄钥匙'),
            (2, 7): (self.key_yellow, '黄钥匙'),
            (4, 9): (self.key_blue, '蓝钥匙'),
            (1, 6): (self.key_blue, '蓝钥匙'),
            (0, 7): (self.hp_red, '红药'),
            (3, 10): (self.hp_red, '红药'),
            (0, 9): (self.hp_blue, '蓝药'),
            (1, 10): (self.gem_red, '红宝石'),
            (1, 8): (self.gem_blue, '蓝宝石'),
            (2, 10): (self.white_warrior, '白衣武士'),
            (2, 8): (self.white_warrior, '白衣武士'),
            (0, 10): (self.shadow_soldier, '影子战士'),
            (4, 10): (self.dark_leader, '冥队长_ss'),
            (0, 6): (self.dark_leader, '冥队长_ss'),
            (4, 8): (self.ling_warrior, '灵武士_ss'),
            (2, 6): (self.ling_warrior, '灵武士_ss'),
            (0, 5): (self.key_red, '红钥匙')
        }
        self.open_up = False

    def fixed_brick(self):
        if self.open_up:        # 十字架交给仙子才会开启上楼
            self.draw(self.upstairs, self.up_pos[0], self.up_pos[1])
            self.dic[self.up_pos] = '上楼'
        self.draw(self.downstairs, self.down_pos[0], self.down_pos[1])
        self.dic[self.down_pos] = '下楼'
        for i in range(5):
            x = 2 * i + 1
            for j in range(5):
                y = 2 * j + 1
                if (x, y) != (5, 7) and (x, y) != (5, 3):
                    self.draw(self.wall, x, y)
                    self.dic[(x, y)] = '墙'
        for i in [(0, 2), (0, 8), (10, 2), (10, 8)]:
            self.draw(self.wall, i[0], i[1])
            self.dic[(i[0], i[1])] = '墙'
        for i in self.ls:
            self.screen.blit(self.road, i)
            self.dic[(int((i[0]-375)/48), int((i[1]-25)/48))] = '路'
